# Maintainer: Jelle van der Waa <jelle@archlinux.org>
# Contributor: David Runge <dvzrv@archlinux.org>
# Contributor: Radek Podgorny <radek@podgorny.cz>
# Contributor: Dan Anderson <dan-anderson at cox dptnet>

pkgname=mosquitto
pkgver=2.0.15
pkgrel=2
pkgdesc="An Open Source MQTT Broker"
arch=(loong64 x86_64)
url="https://mosquitto.org/"
license=(BSD)
depends=(cjson openssl util-linux-libs)
makedepends=(c-ares cmake docbook-xsl libwebsockets systemd uthash)
options=(debug)
source=(
  https://mosquitto.org/files/source/mosquitto-$pkgver.tar.gz{,.asc}
  "$pkgname.service"
  "sysusers_mosquitto.conf"
)
backup=("etc/$pkgname/$pkgname.conf")
sha512sums=('8a0c58222ea0b9304e7f096f6d13965478072baf1d1c9bc931b32a33f5ea8196c2dd54bde8d83fec7ed9cd413cb5fb115ce0a6701ca20664df52fdd7ca63ddaf'
            'SKIP'
            '4789e8ee42f4a8e3ca8e7fd21cb551b5e34991e6ca1750533bbfa555260e20e8ea167bd69b99b407237bcc8969157eee792fdcf3844b839d73310a6c59e5f045'
            '21848b890c2db258138795ec21a009e022b6a8369217eb31939f976ad434229dd9f61d33e8109ade7bc001e8668e9d42b59c1ab079753860417961e102356f0e')
validpgpkeys=('A0D6EEA1DCAE49A635A3B2F0779B22DFB3E717B7')

build() {
  cmake -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_SBINDIR=bin \
        -DCMAKE_INSTALL_SYSCONFDIR=/etc \
        -DCMAKE_BUILD_TYPE=None \
        -DWITH_BUNDLED_DEPS=OFF \
        -DWITH_SRV=ON \
        -DWITH_SYSTEMD=ON \
        -DWITH_WEBSOCKETS=ON \
        -Wno-dev \
        -B build \
        -S "$pkgname-$pkgver"
  make VERBOSE=1 -C build
}

package() {
  depends+=(libcares.so libsystemd.so libwebsockets.so)

  make DESTDIR="$pkgdir/" install -C build

  # TODO: upstream a better systemd service file
  install -vDm 644 "$pkgname.service" -t "$pkgdir/usr/lib/systemd/system/"
  install -vDm 644 "$pkgname-$pkgver/LICENSE.txt" -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 sysusers_mosquitto.conf "${pkgdir}"/usr/lib/sysusers.d/mosquitto.conf
}
